package mysql;
import java.sql.*;
public class DB {
	public static String driver="com.mysql.jdbc.Driver";
	public static String connString="jdbc:mysql://localhost:3306/lucenemanage?useUnicode=true&characterEncoding=UTF-8";
	public static String username="root";
	public static String password="";
	public static Connection getConnection(){
		Connection conn=null;
		try {
			Class.forName(driver).newInstance();
			conn=DriverManager.getConnection(connString,username,password);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.err.println("驱动不存在");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.err.println("数据库连接失败");
		}
		return conn;
	}
	public static void closeConnection(Connection conn) {
		try {
			conn.close(); 
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

	}
	public static void commitConnection(Connection conn){
		try {
			conn.setAutoCommit(false);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

		
	
	
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		Connection conn=DB.getConnection();
//		System.out.println("success!");
//		DB.closeConnection(conn);
//		}
}


